<?php 
namespace Textblast;

class Database {

	protected $_db;
	protected $_dbtype;
	protected $_dbhostname;
	protected $_dbname;
	protected $_dbusername;
	protected $_dbpassword;

	function __construct($dbtype, $hostname, $dbname, $username, $password) {
		$this->_dbtype = $dbtype;
		$this->_dbhostname = $hostname;
		$this->_dbname = $dbname;
		$this->_dbusername = $username;
		$this->_dbpassword = $password;
	}

	function open() {
		try {
			switch ($this->_dbtype) {
				case 'mysql':
					$this->_db = new \PDO("$this->_dbtype:host=$this->_dbhostname;dbname=$this->_dbname", $this->_dbusername, $this->_dbpassword);
					break;
				case 'pgsql':
					$this->_db = new \PDO("$this->_dbtype:dbname=$this->_dbname;host=$this->_dbhostname", $this->_dbusername, $this->_dbpassword);
					break;
				case 'firebird':
					$this->_db = new \PDO("$this->_dbtype:dbname=$this->_dbhostname:$this->_dbname", $this->_dbusername, $this->_dbpassword);
					break;
				case 'OCI':
					$this->_db = new \PDO("$this->_dbtype:", $this->_dbusername, $this->_dbpassword);
					break;
				case 'mongodb':
					$this->_db = new \MongoClient("$this->_dbtype://$this->_dbhostname", array("username" => $this->_dbusername, "password" => $this->_dbpassword));
					break;
			}
/*
new MongoClient("mongodb://localhost", array("username" => $username, "password" => $password));

new PDO("pgsql:dbname=pdo;host=localhost", "username", "password" );
new PDO("sqlite:/path/to/database.sdb");
new PDO("sqlite::memory");
new PDO("mysql:host=$hostname;dbname=mysql", $username, $password);
new PDO("firebird:dbname=localhost:C:\Programs\Firebird\DATABASE.FDB", "SYSDBA", "masterkey");
new PDO("informix:DSN=InformixDB", "username", "password");
new PDO("OCI:", "username", "password")
new PDO("OCI:dbname=accounts;charset=UTF-8", "username", "password");
new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\accounts.mdb;Uid=Admin");
new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$password")
new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=accounts; HOSTNAME=1.2.3,4;PORT=56789;PROTOCOL=TCPIP;", "username", "password");
 */
		} catch (PDOException $e) {
			echo $e->getMessage(); //TODO remove this
		}
		
		return $this->_db;
	}

	function close() {
		$this->_db = null;
	}

	static function PDOSupport() {
		foreach(\PDO::getAvailableDrivers() as $driver) {
	    	echo $driver.'<br />';
	    }
	}
}

/**
* 
*/
class Connect extends Database {

	function __construct() {
		parent::__construct('mysql', 'localhost', 'textblast', 'admin', 'zTMx9FxhLLR6p2AD');	
	}
}
?>
